// `current_manifest` was found on the filesystem with `[workspace]`.
root_manifest: Option<PathBuf>,
- // Allows to override the target directory for the purposes of `cargo install`.
+ // Shared target directory for all the packages of this workspace.
+ // `None` if the default path of `root/target` should be used.
target_dir: Option<Filesystem>,
// List of members in this workspace with a listing of all their manifest
/// before returning it, so `Ok` is only returned for valid workspaces.
pub fn new(manifest_path: &Path, config: &'cfg Config)
-> CargoResult<Workspace<'cfg>> {
+ let target_dir = try!(config.target_dir());
+
let mut ws = Workspace {
config: config,
current_manifest: manifest_path.to_path_buf(),
packages: HashMap::new(),
},
root_manifest: None,
- target_dir: None,
+ target_dir: target_dir,
members: Vec::new(),
};
ws.root_manifest = try!(ws.find_root(manifest_path));
///
/// This is currently only used in niche situations like `cargo install` or
/// `cargo package`.
- pub fn one(package: Package, config: &'cfg Config, target_dir: Option<Filesystem>) -> Workspace<'cfg> {
+ pub fn one(package: Package, config: &'cfg Config, target_dir: Option<Filesystem>)
+ -> CargoResult<Workspace<'cfg>> {
let mut ws = Workspace {
config: config,
current_manifest: package.manifest_path().to_path_buf(),
packages: HashMap::new(),
},
root_manifest: None,
- target_dir: target_dir,
+ target_dir: None,
members: Vec::new(),
};
{
let key = ws.current_manifest.parent().unwrap();
let package = MaybePackage::Package(package);
ws.packages.packages.insert(key.to_path_buf(), package);
+ ws.target_dir = if let Some(dir) = target_dir {
+ Some(dir)
+ } else {
+ try!(ws.config.target_dir())
+ };
ws.members.push(ws.current_manifest.clone());
}
- return ws
+ return Ok(ws)
}
/// Returns the current package of this workspace.
}
pub fn target_dir(&self) -> Filesystem {
- if let Some(ref fs) = self.target_dir {
- return fs.clone()
- }
- if let Some(fs) = self.config.target_dir() {
- return fs.clone()
- }
- Filesystem::new(self.root().join("target"))
+ self.target_dir.clone().unwrap_or_else(|| {
+ Filesystem::new(self.root().join("target"))
+ })
}
/// Returns the root [replace] section of this workspace.
Some(Filesystem::new(config.cwd().join("target-install")))
};
- let ws = Workspace::one(pkg, config, overidden_target_dir);
+ let ws = try!(Workspace::one(pkg, config, overidden_target_dir));
let pkg = try!(ws.current());
// Preflight checks to check up front whether we'll overwrite something.
let new_pkg = Package::new(new_manifest, &manifest_path);
// Now that we've rewritten all our path dependencies, compile it!
- let ws = Workspace::one(new_pkg, config, None);
+ let ws = try!(Workspace::one(new_pkg, config, None));
try!(ops::compile_ws(&ws, None, &ops::CompileOptions {
config: config,
jobs: opts.jobs,
values: LazyCell<HashMap<String, ConfigValue>>,
cwd: PathBuf,
rustdoc: LazyCell<PathBuf>,
- target_dir: Option<Filesystem>,
extra_verbose: Cell<bool>,
frozen: Cell<bool>,
locked: Cell<bool>,
impl Config {
pub fn new(shell: MultiShell,
cwd: PathBuf,
- homedir: PathBuf) -> CargoResult<Config> {
- let mut cfg = Config {
+ homedir: PathBuf) -> Config {
+ Config {
home_path: Filesystem::new(homedir),
shell: RefCell::new(shell),
rustc: LazyCell::new(),
cwd: cwd,
values: LazyCell::new(),
rustdoc: LazyCell::new(),
- target_dir: None,
extra_verbose: Cell::new(false),
frozen: Cell::new(false),
locked: Cell::new(false),
- };
-
- try!(cfg.scrape_target_dir_config());
-
- Ok(cfg)
+ }
}
pub fn default() -> CargoResult<Config> {
human("Cargo couldn't find your home directory. \
This probably means that $HOME was not set.")
}));
- Config::new(shell, cwd, homedir)
+ Ok(Config::new(shell, cwd, homedir))
}
pub fn home(&self) -> &Filesystem { &self.home_path }
pub fn cwd(&self) -> &Path { &self.cwd }
- pub fn target_dir(&self) -> Option<&Filesystem> {
- self.target_dir.as_ref()
+ pub fn target_dir(&self) -> CargoResult<Option<Filesystem>> {
+ if let Some(dir) = env::var_os("CARGO_TARGET_DIR") {
+ Ok(Some(Filesystem::new(self.cwd.join(dir))))
+ } else if let Some(val) = try!(self.get_path("build.target-dir")) {
+ let val = self.cwd.join(val.val);
+ Ok(Some(Filesystem::new(val)))
+ } else {
+ Ok(None)
+ }
}
fn get(&self, key: &str) -> CargoResult<Option<ConfigValue>> {
}
}
- fn scrape_target_dir_config(&mut self) -> CargoResult<()> {
- if let Some(dir) = env::var_os("CARGO_TARGET_DIR") {
- self.target_dir = Some(Filesystem::new(self.cwd.join(dir)));
- } else if let Some(val) = try!(self.get_path("build.target-dir")) {
- let val = self.cwd.join(val.val);
- self.target_dir = Some(Filesystem::new(val));
- }
- Ok(())
- }
-
fn get_tool(&self, tool: &str) -> CargoResult<PathBuf> {
let var = tool.chars().flat_map(|c| c.to_uppercase()).collect::<String>();
if let Some(tool_path) = env::var_os(&var) {